package ovm.gui.views;

import ovm.entity.EntityFactoryEntity;
import ovm.management.administration.factory.EntityFactoryManager;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * Created by IntelliJ IDEA.
 * User: Jokser
 * Date: 28.05.12
 * Time: 10:35
 * To change this template use File | Settings | File Templates.
 */

public class EntityListViewFactory {

    private static final String packagePath = "ovm.gui.views.";
    
    public static AbstractEntityListView createEntityListView (Class entityClass, Boolean editable) {
        // get entity class name
        String entityClassName = entityClass.getSimpleName();
        EntityFactoryEntity properties = EntityFactoryManager.getFactoryProperties(entityClassName);
        if (properties == null) return null;

        // get view class name
        String viewClassName = packagePath + properties.getEntityListView().trim();
        Constructor constructor = null;
        try {
            // get constructor for view class
            constructor = Class.forName(viewClassName).getConstructor(Class.class, Boolean.class);
            // create new view
            return (AbstractEntityListView) constructor.newInstance(entityClass, editable);
        } catch (NoSuchMethodException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        } catch (ClassNotFoundException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        } catch (InvocationTargetException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        } catch (InstantiationException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        } catch (IllegalAccessException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
        return null;
    }


}
